from extensions import db

# 用户信息表
class User(db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(255), nullable=False)
    password = db.Column(db.String(255), nullable=False)

# 种子关键词
class SeedKey(db.Model):
    __tablename__ = "seedkey"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    seedkeyname = db.Column(db.String(255), nullable=False)
    volume = db.Column(db.Integer, nullable=False)
    logdate = db.Column(db.String(255), nullable=False) 
    loglength = db.Column(db.Integer, nullable=False)

# 用户搜索历史
class SearchHistory(db.Model):
    __tablename__ = "searchhistory"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    userid = db.Column(db.String(255), nullable=False)
    seedkeyid = db.Column(db.String(255), nullable=False)
    searchtime = db.Column(db.Integer, nullable=False)

# 种子关键词频率
class SeedKeyFrequency(db.Model):
    __tablename__ = "seedkeyfrequency"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    seedkeyid = db.Column(db.Integer, db.ForeignKey("seedkey.id", ondelete='CASCADE'))
    date = db.Column(db.String(255), nullable=False)
    frequency = db.Column(db.Double, nullable=False)

# 中介关键词
class MidKey(db.Model):
    __tablename__ = "midkey"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    seedkeyid = db.Column(db.Integer, db.ForeignKey("seedkey.id", ondelete='CASCADE'))
    midkeyname = db.Column(db.String(255), nullable=False)
    midkeyvalue = db.Column(db.Double, nullable=False)
    
# 竞争性关键词
class Compkey(db.Model):
    __tablename__ = "compkey"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    seedkeyid = db.Column(db.Integer, db.ForeignKey("seedkey.id", ondelete='CASCADE'))
    midkeyid = db.Column(db.Integer, db.ForeignKey("midkey.id", ondelete='CASCADE'))
    compkeyname = db.Column(db.String(255), nullable=False)
    compkeyvalue = db.Column(db.Double, nullable=False)

# 竞争性关键词频率
class CompKeyFrequency(db.Model):
    __tablename__ = "compkeyfrequency"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    compkeyid = db.Column(db.Integer, db.ForeignKey("compkey.id", ondelete='CASCADE'))
    date = db.Column(db.String(255), nullable=False)
    frequency = db.Column(db.Double, nullable=False)

# 最终排序的竞争性关键词
class CompkeyFinal(db.Model):
    __tablename__ = "compkeyfinal"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    seedkeyid = db.Column(db.Integer, db.ForeignKey("seedkey.id", ondelete='CASCADE'))
    compkeyname = db.Column(db.String(255), nullable=False)
    value = db.Column(db.Double, nullable=False)